using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class AddFreindPage : BasePage
	{
		private const string TAG = "AddFreindPage";
		private EventWatcher mWatchxxx;
		private object mObjectWatcher;
		private bool mBIsSetPlugins;
		private List<PluginBase> mListPlugins = new List<PluginBase>();
		private static Thickness mPanelMargin = new Thickness(0.0, 28.0, 0.0, 0.0);
		private List<StackPanel> listPanels;
		private List<PluginBase> listHardCodePlugins;
		private PluginBaseEx pluginQRCode;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal StackPanel panelPluginHolder;
		private bool _contentLoaded;
		public AddFreindPage()
		{
			List<StackPanel> list = new List<StackPanel>();
			List<StackPanel> arg_50_0 = list;
			StackPanel stackPanel = new StackPanel();
			stackPanel.set_Visibility(1);
			stackPanel.set_Margin(new Thickness(0.0, -12.0, 0.0, 0.0));
			arg_50_0.Add(stackPanel);
			this.listPanels = list;
			this.listHardCodePlugins = new List<PluginBase>();
			base..ctor();
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("AddFreindPage", "Page_Loaded");
			this.refreshPlugins();
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("AddFreindPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("AddFreindPage", "OnPageIn");
			this.getPlugins();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("AddFreindPage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("AddFreindPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void Btn_SearchFriend(object sender, object object_0)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/AddFriends/AddFriendBy.xaml", null, false);
		}
		private void Btn_QQFriend(object sender, RoutedEventArgs e)
		{
			Account curAccount = AccountMgr.getCurAccount();
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage != null)
			{
				string text = "findFriend";
				object[] object_ = new object[]
				{
					text
				};
				if (curAccount.nBindQQ != 0u)
				{
					basePage.GoToPage("/Source/Plugin/Common/QQInfo/UI/ViewQQGroups.xaml", object_, false);
					return;
				}
				basePage.GoToPage("/Source/UI/QQFriends/GoBindQQ.xaml", object_, false);
			}
		}
		private void Btn_MobileContact(object sender, object object_0)
		{
			AccountMgr.getCurAccount();
			if (ConfigMgr.getBool("bIsEnabledAddrBookMatch", false) && ToolFunction.checkIsPhoneNumber(AccountMgr.strBindMobile) && AccountMgr.MobileVerify)
			{
				ToolFunction.GotoPageForUserControl("/Source/UI/PhoneContact/ViewPhoneContact.xaml", null, false);
				return;
			}
			ToolFunction.GotoPageForUserControl("/Source/UI/PhoneContact/PhoneNumBinding.xaml", null, false);
		}
		private void Btn_VerifyUser(object sender, object object_0)
		{
			string text = R.isChineseCN() ? "zh_CN" : "en";
			WebViewPageConfig config = new WebViewPageConfig
			{
				strUrl = "http://open.weixin.qq.com/biz/all?lang=" + text,
				mBHideAppbar = true
			};
			ToolFunction.GotoWebLinkInWebView(config, GetA8KeyScene.MMGETA8KEY_SCENE_UNKNOW);
		}
		private void initUI()
		{
		}
		private void getPlugins()
		{
			if (this.mBIsSetPlugins)
			{
				return;
			}
			this.mBIsSetPlugins = true;
			this.initPluginPanels();
			this.hardCodePlugins();
			List<PluginBase> list = ExtentCenter.getListInTab(MainTabIndex.AddFriendList);
			if (list == null)
			{
				list = new List<PluginBase>();
			}
			using (List<PluginBase>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					PluginBase current = enumerator.get_Current();
					if (!this.mListPlugins.Contains(current))
					{
						this.mListPlugins.Add(current);
						this.addPluginToPanel(current);
					}
				}
			}
			for (int i = 0; i < this.mListPlugins.get_Count(); i++)
			{
				PluginBase pluginBase = this.mListPlugins.get_Item(i);
				if (!list.Contains(pluginBase))
				{
					this.mListPlugins.Remove(pluginBase);
					this.removePluginFromPanel(pluginBase);
					i--;
				}
			}
		}
		private void refreshPlugins()
		{
			this.mBIsSetPlugins = false;
			this.getPlugins();
		}
		private void initPluginPanels()
		{
			if (this.panelPluginHolder.get_Children().get_Count() != 0)
			{
				return;
			}
			using (List<StackPanel>.Enumerator enumerator = this.listPanels.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					StackPanel current = enumerator.get_Current();
					this.panelPluginHolder.get_Children().Add(current);
				}
			}
			using (List<StackPanel>.Enumerator enumerator2 = this.listPanels.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					StackPanel current2 = enumerator2.get_Current();
					if (current2.get_Children().get_Count() == 0)
					{
						for (int i = 0; i < 5; i++)
						{
							PluginEntranceItemCtrl pluginEntranceItemCtrl = new PluginEntranceItemCtrl();
							pluginEntranceItemCtrl.txtTitle.set_Foreground(MMTheme.GetInstance().FIND_FRIEND_BUTTON_BK_FOCUS_BRUSH);
							pluginEntranceItemCtrl.set_Visibility(1);
							current2.get_Children().Add(pluginEntranceItemCtrl);
						}
					}
				}
			}
		}
		private void hardCodePlugins()
		{
			if (this.listHardCodePlugins.get_Count() != 0)
			{
				return;
			}
			BitmapImage mIconInFFEntry;
			if (MMTheme.IsCoolBlackTheme())
			{
				mIconInFFEntry = new BitmapImage(new Uri("/Resource/Img/CommonUse/addByNum_cool.png", 2));
			}
			else
			{
				mIconInFFEntry = new BitmapImage(new Uri("/Resource/Img/CommonUse/addByNum_light.png", 2));
			}
			PluginBaseEx pluginAddFreind = new PluginBaseEx
			{
				mIndexInGroup = 0,
				mIndexInPosition = 0,
				mFFEntryTitle = strings.FF_Entry_SearchFriend,
				mIconInFFEntry = mIconInFFEntry
			};
			PluginEntranceItemCtrl pluginEntranceItemCtrl = this.listPanels.get_Item(pluginAddFreind.mIndexInGroup).get_Children().get_Item(pluginAddFreind.mIndexInPosition) as PluginEntranceItemCtrl;
			pluginEntranceItemCtrl.ItemClick += new PluginEntranceItemCtrl.ListItemClick(this.Btn_SearchFriend);
			this.addPluginToPanel(pluginAddFreind);
			this.listHardCodePlugins.Add(pluginAddFreind);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				pluginAddFreind.OnShowInFFEntry();
			});
			PluginBaseEx pluginAddByMoblie = new PluginBaseEx
			{
				mIndexInGroup = 0,
				mIndexInPosition = 2,
				mFFEntryTitle = strings.FF_Entry_PhoneContactFriend,
				mIconInFFEntry = ImageCacheMgr.loadFromRes(MMTheme.GetInstance().mobileContact_main)
			};
			pluginAddByMoblie.OnShowInFFEntry();
			PluginEntranceItemCtrl pluginEntranceItemCtrl2 = this.listPanels.get_Item(pluginAddByMoblie.mIndexInGroup).get_Children().get_Item(pluginAddByMoblie.mIndexInPosition) as PluginEntranceItemCtrl;
			pluginEntranceItemCtrl2.ItemClick += new PluginEntranceItemCtrl.ListItemClick(this.Btn_MobileContact);
			this.addPluginToPanel(pluginAddByMoblie);
			this.listHardCodePlugins.Add(pluginAddByMoblie);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				pluginAddByMoblie.OnShowInFFEntry();
			});
			PluginBaseEx pluginBaseEx = new PluginBaseEx
			{
				mIndexInGroup = 0,
				mIndexInPosition = 4,
				mFFEntryTitle = strings.FF_Entry_StarList,
				mIconInFFEntry = ToolFunction.GetImgFromContentSource("/Resource/Img/CommonUse/VerifidContactWebIcon.png")
			};
			PluginEntranceItemCtrl pluginEntranceItemCtrl3 = this.listPanels.get_Item(pluginBaseEx.mIndexInGroup).get_Children().get_Item(pluginBaseEx.mIndexInPosition) as PluginEntranceItemCtrl;
			pluginEntranceItemCtrl3.ItemClick += new PluginEntranceItemCtrl.ListItemClick(this.Btn_VerifyUser);
			this.addPluginToPanel(pluginBaseEx);
			this.listHardCodePlugins.Add(pluginBaseEx);
		}
		private void addPluginToPanel(PluginBase plugin)
		{
			if (plugin.mIndexInGroup >= this.listPanels.get_Count() || plugin.mIndexInPosition >= this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Count())
			{
				return;
			}
			if (!(this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Item(plugin.mIndexInPosition) is PluginEntranceItemCtrl))
			{
				return;
			}
			this.listPanels.get_Item(plugin.mIndexInGroup).set_Visibility(0);
			PluginEntranceItemCtrl pluginEntranceItemCtrl = this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Item(plugin.mIndexInPosition) as PluginEntranceItemCtrl;
			if (pluginEntranceItemCtrl.ItemObject == null)
			{
				pluginEntranceItemCtrl.ItemObject = plugin;
				pluginEntranceItemCtrl.set_Visibility(0);
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				plugin.OnShowInFFEntry();
			});
		}
		private void removePluginFromPanel(PluginBase plugin)
		{
			if (this.listHardCodePlugins.Contains(plugin))
			{
				return;
			}
			if (plugin.mIndexInGroup >= this.listPanels.get_Count() || plugin.mIndexInPosition >= this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Count())
			{
				return;
			}
			if (!(this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Item(plugin.mIndexInPosition) is PluginEntranceItemCtrl))
			{
				return;
			}
			PluginEntranceItemCtrl pluginEntranceItemCtrl = this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().get_Item(plugin.mIndexInPosition) as PluginEntranceItemCtrl;
			pluginEntranceItemCtrl.ItemObject = null;
			pluginEntranceItemCtrl.set_Visibility(1);
			using (IEnumerator<UIElement> enumerator = this.listPanels.get_Item(plugin.mIndexInGroup).get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					UIElement current = enumerator.get_Current();
					if (current.get_Visibility() == null)
					{
						return;
					}
				}
			}
			this.listPanels.get_Item(plugin.mIndexInGroup).set_Visibility(1);
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/AddFreindPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.panelPluginHolder = (StackPanel)base.FindName("panelPluginHolder");
		}
	}
}
